[XEN][POWERPC] Fix allocation error for xencomm "mini" descriptors.
authorHollis Blanchard <hollisb@us.ibm.com>
Fri, 8 Sep 2006 15:23:56 +0000 (10:23 -0500)
committerHollis Blanchard <hollisb@us.ibm.com>
Fri, 8 Sep 2006 15:23:56 +0000 (10:23 -0500)
Previous code worked correctly only if the allocated structure fit in the same
page as the base address. If the structure did not fit, the computation for the
allocation was incorrect. Noticed by Kiyokuni KAWACHIYA <KAWATIYA@jp.ibm.com>.

Signed-off-by: Maria Butrico <butrico@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
xen/arch/powerpc/of_handler/xencomm.c

index 867fcd77b34fe2425b0b021eb34c001ebb9fe63c..b82acbacf2dbe99bc4050f47f06b23341e8a9d54 100644 (file)
@@ -50,18 +50,18 @@ static int __xencomm_init(struct xencomm_desc *desc, void *buffer,
 static void *__xencomm_alloc_mini(void *area, int arealen)
 {
     unsigned long base = (unsigned long)area;
-    unsigned int pageoffset;
+    unsigned int left_in_page;
 
-    pageoffset = base % PAGE_SIZE;
+    left_in_page = PAGE_SIZE - base % PAGE_SIZE;
 
     /* we probably fit right at the front of area */
-    if ((PAGE_SIZE - pageoffset) >= sizeof(struct xencomm_mini)) {
+    if (left_in_page >= sizeof(struct xencomm_mini)) {
         return area;
     }
 
     /* if not, see if area is big enough to advance to the next page */
-    if ((arealen - pageoffset) >= sizeof(struct xencomm_mini))
-        return (void *)(base + pageoffset);
+    if ((arealen - left_in_page) >= sizeof(struct xencomm_mini))
+        return (void *)(base + left_in_page);
 
     /* area was too small */
     return NULL;